package com.qiniuyun.graph.api.user;

import com.qiniuyun.graph.common.service.UserService;
import com.qiniuyun.graph.common.utils.IpUtil;
import com.qiniuyun.graph.common.utils.ResultVOUtil;
import com.qiniuyun.graph.common.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/graph")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/token")
    public ResultVO getToken(@RequestParam("signature") @NotEmpty(message = "signature can not be empty") String signature,
                             HttpServletRequest request) {
        String ipAddress = IpUtil.getIpAddr(request);
        return ResultVOUtil.success(userService.getTokenByIp(ipAddress, signature));
    }

}
